package routes

import (
	gs "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	"go_wep_demo/controllers"
	_ "go_wep_demo/docs" // 千万不要忘了导入把你上一步生成的docs
	"go_wep_demo/logger"
	"go_wep_demo/middlewares"
	"go_wep_demo/settings"
	"net/http"

	"github.com/gin-gonic/gin"
)

func Init() *gin.Engine {
	// 创建一个默认的路由引擎
	if settings.Config.AppConfig.Mode == gin.ReleaseMode {
		gin.SetMode(gin.ReleaseMode)
	}
	r := gin.New()
	r.Use(logger.GinLogger(), logger.GinRecovery(true))
	r.GET("/hello", func(context *gin.Context) {
		context.String(http.StatusOK, "dddds")
		return
	})
	r.GET("/swagger/*any", gs.WrapHandler(swaggerFiles.Handler))
	//r.GET("/swagger/*any", gs.DisablingWrapHandler(swaggerFiles.Handler, "NAME_OF_ENV_VARIABLE"))
	r.POST("/signup", controllers.SignUpHandler)
	r.POST("/login", controllers.LoginHandler)
	r.POST("/refreshToken", controllers.RefreshTokenHandler)
	v1 := r.Group("/v1", middlewares.JWTAuthMiddleware())
	{
		v1.GET("/getArticleTypeList", controllers.GetTypeListHandler)
		v1.POST("/addArticle", controllers.SaveArticleHandler)
		v1.GET("/getArticle/:article_id", controllers.GetArticleHandler)
		v1.POST("/addVote", controllers.AddVoteHandler)
	}

	return r
}
